{extend name="v1/layout/base"}
{block name="content"}
<div class="layuimini-main">

  <fieldset class="table-search-fieldset xk-search-status" id="xk-search-status">
    <legend>搜索信息</legend>
    <div style="margin: 10px 10px 10px 10px">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card-body layui-form layui-form-pane">
            <div class="layui-row layui-col-space10 layui-form-item">
              <div class="layui-col-lg12">
                <label class="layui-form-label">搜索关键词</label>
                <div class="layui-input-block">
                  <input type="text" name="keywords" placeholder="请输入搜索关键词" id="keywords" class="layui-input">
                </div>
              </div>
            </div>
            <div class="layui-row layui-col-space10 layui-form-item">
              <div class="layui-col-lg12">
                <label class="layui-form-label">创建时间</label>
                <div class="layui-input-block">
                  <input type="text" class="layui-input" autocomplete="off" id="search_time" placeholder="请选择对应的下单时间范围">
                </div>
              </div>
            </div>
            <div class="layui-row layui-col-space10 layui-form-item">
              <div class="layui-col-lg12">
                <label class="layui-form-label">支付方式</label>
                <div class="layui-input-block">
                  <input type="checkbox" class="layui-input" name="pay_type" value="1" title="微信支付">
                  <!-- <input type="checkbox" class="layui-input" name="pay_type" value="2" title="对公打款"> -->
                </div>
              </div>
            </div>
            <div class="layui-row layui-col-space10 layui-form-item">
              <div class="layui-col-lg12">
                <label class="layui-form-label">是否完成结算</label>
                <div class="layui-input-block">
                  <input type="checkbox" class="layui-input" name="status" value="0" title="未结算">
                  <input type="checkbox" class="layui-input" name="status" value="1" title="已结算">
                </div>
              </div>
            </div>
            <div class="layui-row">
              <div class="layui-col-xs4">&nbsp;</div>
              <div class="layui-col-xs4">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius close-search"><i class="layui-icon">&#x1007;</i>关闭</button>
                <button type="button" class="layui-btn layui-btn-normal layui-btn-radius xk-dosearch">搜索<i class="layui-icon"></i></button>
              </div>
              <div class="layui-col-xs4">&nbsp;</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </fieldset>

  <script type="text/html" id="toolbar">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-black  layui-btn-sm" lay-event="reseve"><i class="layui-icon">&#xe63d;</i></button>
      <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export"><i class="layui-icon">&#xe67d;</i>导出筛选后的数据</button>
      <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="search"><i class="layui-icon"></i>搜索</button>
    </div>
  </script>

  <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
</div>
{/block}
{block name="myScript"}
<script>
  layui.use(['form', 'table', 'laydate'], function() {
    var $ = layui.jquery,
      form = layui.form,
      table = layui.table;
    var laydate = layui.laydate;
    laydate.render({
      elem: '#search_time',
      range: '~',
      theme: '#1E9FFF',
      format: 'yyyy-MM-dd'
    });
    table.render({
      elem: '#currentTableId',
      url: '/{:config("manage.manage_name")}/{:config("manage.version")}/Finance/userWithdrawal',
      toolbar: '#toolbar',
      defaultToolbar: ['filter',{
        title: '搜索',
        layEvent: 'search',
        icon: 'layui-icon-search'
      }],
      height: 'full-50',
      cols: [
        [{
            field: 'second_with_drawal_id',
            width: '5%',
            title: 'ID',
            sort: true
          },
          {
            field: 'user_name',
            width: '10%',
            title: '会员昵称'
          },
          {
            field: 'withdrawal_sn',
            width: '10%',
            title: '提现单号'
          },
          {
            field: 'money',
            width: '8%',
            title: '申请金额'
          },
          {
            field: 'sure_money',
            width: '8%',
            title: '实际到账金额'
          },
          {
            field: 'service_charge',
            width: '8%',
            title: '手续费'
          },
          {
            field: 'status',
            width: '10%',
            title: '提现状态'
          },
          {
            field: 'create_time',
            title: '变动时间'
          }
        ]
      ],
      limits: [100, 150, 200, 250, 500, 1000],
      limit: 100,
      id: 'table_ids',
      page: true,
      skin: 'line'
    });
    // 顶部操作工具
    table.on('toolbar(currentTableFilter)', function(obj) {
      var url = $(this).attr('data-url');
      switch (obj.event) {
        case 'reseve':
          table.reload('table_ids');
          break;
        case 'export':
          var keywords = $("#keywords").val(),
            search_time = $("#search_time").val(),
            pay_type_arr = [],
            pay_type = '',
            act_arr = [],
            act = ''
          entry_arr = [],
            entry = '';
          $("input[name=pay_type]:checked").each(function() {
            pay_type_arr.push($(this).val());
          });
          pay_type = pay_type_arr.join(',');
          $("input[name=act]:checked").each(function() {
            act_arr.push($(this).val());
          });
          act = act_arr.join(','),
            $("input[name=entry]:checked").each(function() {
              entry_arr.push($(this).val());
            });
          entry = entry_arr.join(','),
            url = "/{:config('manage.manage_name')}/{:config('manage.version')}/Finance/exportFinance";
          https(url, {
            keywords: keywords,
            search_time: search_time,
            entry: entry,
            act: act,
            pay_type: pay_type
          }, 'post', true, '正在执行财务数据导出').then(res => {
            if (res.result_code == 200) {
              var html = '<h1 style="padding: 0 20px;color:red;font-size:18px;margin-bottom:15px;">如果数据量大于1万条系统自动分表导出</h1>';
              res.resultData.forEach(function(value, index) {
                html += '<h2 style="padding: 0 20px;font-size:16px;">第' + (index + 1) + '个订单文件：<a href="' + value + '">' + '下载' + '</a></h2>';
              })
              layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['400px', '200px'], //宽高
                content: html
              });
            }
          })
          break;
        case 'search':
          $("#xk-search-status").removeClass('xk-search-status');
          break;
      }
    })
    // 执行搜索
    $(".xk-dosearch").click(function() {
      var keywords = $("#keywords").val(),
        search_time = $("#search_time").val(),
        pay_type_arr = [],
        pay_type = '',
        act_arr = [],
        act = '',
        entry_arr = [],
        entry = '';
      $("input[name=pay_type]:checked").each(function() {
        pay_type_arr.push($(this).val());
      });
      pay_type = pay_type_arr.join(',');
      $("input[name=act]:checked").each(function() {
        act_arr.push($(this).val());
      });
      act = act_arr.join(','),
        $("input[name=entry]:checked").each(function() {
          entry_arr.push($(this).val());
        });
      entry = entry_arr.join(',');
      table.reload('table_ids', {
        page: {
          curr: 1
        },
        where: {
          keywords: keywords,
          search_time: search_time,
          act: act,
          entry: entry,
          pay_type: pay_type
        }
      }, 'data');
    })
  });
</script>
{/block}
